package com.etbsms.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.etbsms.dao.IUsersDAO;

public class SecurityManager implements UserDetailsService {


	@Autowired
	private IUsersDAO usersDAO;

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {	
		
		
		
		User user = usersDAO.findUserByUsername(username);		
		if (user != null)
			return user;
		
		throw new UsernameNotFoundException("User :" + username
				+ " has no GrantedAuthority");
	}
}
